package com.jims.master.modules.sys.service;

import com.jims.master.common.service.CrudService;
import com.jims.master.modules.sys.dao.UserDao;
import com.jims.master.modules.sys.entity.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by qinlongxin on 2017-05-04.
 */
@Service
public class UserService  extends CrudService<UserDao,User> {

    @Transactional(readOnly = false)
    public int updatePasswordById(User user){
        return this.dao.updatePasswordById(user);
    }
    @Transactional(readOnly = false)
    public int update(User user){return  this.dao.update(user);}

    /**
     * 更新用戶類型
     * @param userType
     * @param openid
     * @param persionId
     * @return
     */
    public int updateUserType(String userType,String openid ,String persionId){
        return dao.updateUserType(userType,openid,persionId);
    }

    public User findUserDocOpenId(String openid){
        return dao.findUserByOpenid(openid);
    }

    /**
     * 更新信息同步到网易平台user
     * @param user
     * @return
     */
    @Transactional(readOnly = false)
    public int updateToken(User user){return this.dao.updateToken(user);}
    /**
     * 根据baseinfoId查找user信息
     * @param baseinfoId
     * @return
     */
    public User findUserByPersonId(String baseinfoId){return  this.dao.findUserByPersonId(baseinfoId);}
    /**
     * 根据openid查询user
     * @param openid
     * @return
     */
    public User findUserByOpenid(String  openid){
        User user=null;
        user =this.dao.findUserByOpenid(openid);
        /*if("2".equals(userType)){
            user =this.dao.findUserByDocOpenid(openid);
        }else{
            user =this.dao.findUserByOpenid(openid);
        }*/
        return user;
    }
    /**
     * 更新openid
     * @param user
     * @return
     */
    @Transactional(readOnly = false)
    public int updateOpenid(User user){return this.dao.updateOpenid(user);}
    /**
     * 根据qqOqenid查询user
     * @param qq0penid
     * @return
     */
    public User findUserByqqOpenid(String qq0penid){
        return this.dao.findUserByqqOpenid(qq0penid);
    }

    /**
     * 用户总数
     * @param user
     * @return
     */
    public int personCount(User user){
        return dao.personCount(user);
    }
    /**
     * 根据baseinfoId查找user信息
     * @param baseinfoId
     * @return
     *//*
    public User findUserByBaseinfoId(String baseinfoId){
        return dao.findUserByBaseinfoId(baseinfoId);
    }*/

    /**
     * 更新persionId
     * @param user
     * @return
     */
    @Transactional(readOnly = false)
    public int updatePersionId (User user){return dao.updatePersionId(user);}
    /**
     * 通过网易关联找号查找
     * @param account
     * @return
     */
    @Transactional(readOnly = true)
    public User findUserByAccount (String account){return dao.findUserByAccount(account);}
    /**
     * 根据登录名称查询用户
     * @param user
     * @return
     * @author WangYQ
     * @date 2018-02-01
     */
    @Transactional(readOnly = true)
    public User getByLoginName(User user){return dao.getByLoginName(user);}
}
